const {ccclass, property} = cc._decorator;
import SoundManager from '../manager/SoundManager';
import PrefabManager from '../xf/manager/PrefabManager';
import Plat from '../xf/Palt';
import ViewBase from '../xf/ViewBase';
import AndroidTool from './AndroidTool';
import MdGame from './MdGame';


@ccclass
export default class MdWin extends ViewBase {

    private static _inst:MdWin;

    public static get inst()
    {
        if(this._inst==null)
        {
            let v=cc.instantiate(PrefabManager.getPrefab("WinView"));

            this._inst=v.getComponent(MdWin);
        }

        return this._inst;
    }

    protected onLoad(): void {
        var self=this
        let helper = { 
            ok : function(){
                self.nextGame()
            }
        }
        window["winner"]=helper;
    }

    public showView(data?: any): void {
        super.showView(data)
        SoundManager.playSound("winner")
        if(AndroidTool.Instance.isAndroid()){
            AndroidTool.Instance.onWinViewShow()
        }
    }

    public hideView(): void {
        if(AndroidTool.Instance.isAndroid()){
            AndroidTool.Instance.onWinViewHide()
        }
        super.hideView()
    }

    public startGame()
    {
        if(AndroidTool.Instance.isAndroid()){
            AndroidTool.Instance.onNextLevel()
            return;
        }
        this.nextGame()
    }

    public nextGame(){
        this.hideView();
        MdGame.inst.startGame();
    }

    public onShare()
    {
        Plat.shareAppMessage();
    }
   
    

}